# coding=utf-8

import re

# 处理用的正则式list
# 三个元素分别为：匹配正则，flags，替换
sample_re_list = (
            # 示例
            [
                r'',
                0,
                r''
            ],
            )  

def replace(text, re_list):
    '''用re_list进行替换处理'''
    print('>用正则式列表替换')
    
    # 编译
    for i in re_list:
        i.append(re.compile(''.join(i[0]), i[1]))
        #print(''.join(i[0]))

    process_count = 0
    for r in re_list:
        text, n = r[3].subn(r[2], text)
        process_count += 1 if n > 0 else 0

    print('...共%d个正则，做了%d次替换' % (len(re_list), process_count))
    return text
